<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Http\Events\RequestHandled;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class RequestResponseListener
{
    /**
     * Handle the event.
     */
    public function handle(RequestHandled $handled): void
    {
        Log::channel('response')->info($handled->request->url(), [
            'ip'                => $handled->request->ip(),
            'method'            => $handled->request->method(),
            'headers'           => $handled->request->headers->all(),
            'request'           => $handled->request->all(),
            'response'          => $handled->response->getContent(),
            'responseHeaders'   => $handled->response->headers->all(),
            'attributes'        => $handled->request->attributes->all(),
        ]);
    }
}
